# coding: utf-8

from django.db import models

from main.modelfields import encrypt_field


class OpLog(models.Model):
    """
    操作日志
    """
    OBJECT_TYPE_CHOICES = (
        ('user', '用户'),
        ('group', '用户组'),
        ('staff', '职员信息'),
    )
    object_id = models.PositiveIntegerField(
        '日志对象ID',
        db_index=True,
    )
    object_type = models.CharField(
        '日志对象类别',
        max_length=30,
        choices=OBJECT_TYPE_CHOICES,
        db_index=True,
    )
    operator_time = models.DateTimeField(
        '操作时间',
        auto_now_add=True,
    )
    log_type = models.CharField(
        '日志类别',
        max_length=100,
        default='',
        blank=True,
    )
    log = encrypt_field.EncryptTextField(
        '操作日志',
    )
    user_id = models.IntegerField(
        "用户id",
        help_text="用户id",
        null=True,
        blank=True,
    )
    operator = models.CharField(
        '操作人',
        max_length=50,
    )

    def __str__(self):
        return self.log

    class Meta:
        verbose_name = '操作日志'
        verbose_name_plural = verbose_name
